import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config'; // 新增
import { UploadService } from './upload.service';
import { UploadController } from './upload.controller';
import * as aliOss from 'ali-oss';

@Module({
  imports: [ConfigModule], // 导入ConfigModule
  controllers: [UploadController],
  providers: [
    UploadService,
    {
      provide: 'ALIOSS_CLIENT',
      useFactory: (configService: ConfigService) => {
        return new aliOss({
          accessKeyId: configService.get('alioss.access_key_id'),
          accessKeySecret: configService.get('alioss.access_key_secret'),
          bucket: configService.get('alioss.bucket_name'),
          region: configService.get('alioss.region'),
          secure: true,
        });
      },
      inject: [ConfigService], // 声明依赖
    },
  ],
})
export class UploadModule {}
